import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { Descriptions, message } from "antd";
import "./index.less";
import { useState } from "react";
import { invoiceInfoApi } from "@/api/statisticalReport/departmentalFinancialAccounting";
import { useTranslation } from "react-i18next";
let reload: Function;
let id: string;
const { Item } = Descriptions;
const index = (props: { register: Fn }) => {
	const { t } = useTranslation();
	const en_vi = "statisticalReport.InvoiceLnformation";
	const [record, setRecord] = useState<any>({});
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, async data => {
		reload = data.reload;
		setRecord(data.record);
		id = data.record.id;
	});

	const handleSubmit = async () => {
		console.log(id);
		const res = await invoiceInfoApi.invoiceInfoUpdate({
			id,
			status: 1
		});
		if (!res) message.error(t(`${en_vi}.issuanceFailed`));
		message.success(t(`${en_vi}.issuedSuccessfully`));
		closeDrawer();
		reload();
		id = "";
	};
	return (
		<BasicDrawer showFooter={true} {...props} register={registerDrawer} ok={handleSubmit}>
			<Descriptions column={1} layout="horizontal">
				<Item label={t(`${en_vi}.invoiceCode`)}>{record.invoiceNo}</Item>
				<Item label={t(`${en_vi}.invoiceType`)}>
					{record.invoiceType == "1" ? t(`${en_vi}.specialVATInvoice`) : t(`${en_vi}.generalInvoice`)}
				</Item>
				<Item label={t(`${en_vi}.buyerName`)}>{record.buyerName}</Item>
				<Item label={t(`${en_vi}.sellerName`)}>{record.sellerName}</Item>
				<Item label={t(`${en_vi}.totalAmount`)}>{record.totalAmount}</Item>
				<Item label={t(`${en_vi}.taxAmount`)}>{record.taxAmount}</Item>
				<Item label={t(`${en_vi}.remarks`)}>{record.remarks}</Item>
			</Descriptions>
		</BasicDrawer>
	);
};
export default index;
